#ifndef	_MAIN_FORM_H_
#define 	_MAIN_FORM_H_

//#include <gtkmm/main.h>
#include "common.h"
#include "value_list_view.h"
#include "key_tree_view.h"

namespace Gtk{
class TreeView;
class	TreeModel;
}
class Hive_Accessor;

class Main_Form : public Gtk::Window
{
public:
	Main_Form();
	virtual ~Main_Form();

	friend void
	travel_path_for_show_all_subkeys(const char *path, struct nk_key * key_data, void *userdata);
	friend void
	travel_key_for_show_all_values(const char * name, struct vk_key * val_data, void * userdata);
protected:
	void key_model_initialize();

	class TreeViewColumns : public Gtk::TreeModel::ColumnRecord
	{
		public:
		Gtk::TreeModelColumn<Glib::ustring>	path_;
		TreeViewColumns() { add(path_);}
	};
	TreeViewColumns tree_columns_;

	class ListViewColumns : public Gtk::TreeModel::ColumnRecord
	{
		public:
		Gtk::TreeModelColumn<Glib::ustring>	name_;
		Gtk::TreeModelColumn<Glib::ustring>	type_;
		Gtk::TreeModelColumn<Glib::ustring>	data_;
		ListViewColumns() { add(name_); add(type_); add(data_);}
	};
	ListViewColumns list_columns_;

protected:
	virtual bool 	on_button_release_event(GdkEventButton* event);
	virtual void	treeviewcolumn_validated_on_cell_data(Gtk::CellRenderer* renderer, const Gtk::TreeModel::iterator& iter);
	virtual void	cellrenderer_validated_on_editing_started(Gtk::CellEditable* cell_editable, const Glib::ustring& path);
	virtual void	cellrenderer_validated_on_edited(const Glib::ustring& path_string, const Glib::ustring& new_text);

private:
	//Signal handlers:
	void	on_tree_row_expanded(const Gtk::TreeModel::iterator & iter,
	const Gtk::TreeModel::Path & path);
	void	on_change_cursor();
	void	on_view_dblclick(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column);
	void	on_value_delete(const Gtk::TreeModel::iterator & iter);
	void	on_key_delete(const Gtk::TreeModel::iterator & iter);
	void	on_key_whole_path_copy(const Gtk::TreeModel::iterator & iter);
	void	on_key_export(const Gtk::TreeModel::iterator & iter);
	void	on_key_create(const Gtk::TreeModel::iterator & iter);
	void	on_menu_about();
	void	on_menu_quit();

	int	add_menu_bar();
	int	create_popup_menu();
	bool	reg_relation_analyzer(const Glib::ustring & whole_path, Glib::ustring & root,
	Glib::ustring & subkey) const;
	Glib::ustring get_whole_key_name_from_path_string(Glib::ustring path_string) const;
	void	path_split_for_tree_store(const Gtk::TreeModel::iterator & iter, const Glib::ustring & path);
	//Member widgets:
	Glib::RefPtr<Gtk::UIManager> ui_manager_;
	Glib::RefPtr<Gtk::ActionGroup> action_group_;

	Glib::RefPtr<Gtk::UIManager> left_popup_ui_manager_;
	Glib::RefPtr<Gtk::ActionGroup> left_popup_action_group_;
	Glib::RefPtr<Gtk::UIManager> right_popup_ui_manager_;
	Glib::RefPtr<Gtk::ActionGroup> right_popup_action_group_;

	Gtk::Menu * right_menu_popup;
	Gtk::Statusbar status_bar_;
	Gtk::VBox vbox_;
	Key_Tree_View key_tree_;
	Value_List_View val_view_;
	Glib::RefPtr<Gtk::TreeStore>	key_model_;
	Glib::RefPtr<Gtk::ListStore>	val_model_;
	guint context_id_;
	Hive_Accessor * reg_;
	Gtk::TreeModel::iterator	select_iter_;
	Glib::ustring	current_key_path_;
	Gtk::CellRendererText cellrenderer_validated_;
	Gtk::TreeView::Column treeviewcolumn_validated_;
	bool	validate_retry_;
	Glib::ustring invalid_text_for_retry_;
};

void
travel_path_for_show_all_subkeys(const char *path, struct nk_key * key_data, void *userdata);

void
travel_key_for_show_all_values(const char * name, struct vk_key * val_data, void * userdata);

std::string
get_data_in_string(const Hive_Accessor *reg, const std::string & name);

#endif // _MAIN_FORM_H_
